require "Common/define"
require "proto/shop/message/ReqShopItemListMessage"
require "proto/shop/message/ReqRefreshShopMessage"
require "proto/shop/message/ReqBuyItemMessage"

shopHandler = shopHandler or {};
G.serverData = G.serverData or {};
local this = shopHandler;
local sub_type = Config.sub_type_shop

--- 商城商品列表返回
function shopHandler.GetShopItemData(msg)
    --log("=========shopHandler.GetShopItemData====>");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        logicMgr.ShopManager.resShopData(msg.shop);
    end
end

--- 刷新商店返回(第几次刷新)
function shopHandler.ResRefShopData(msg)
    --log("=========shopHandler.ResRefShopData====>");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        logicMgr.ShopManager.refreshShopData(msg);
    end
end

--- 刷新商店返回(刷新时间)
function shopHandler.ResRefShopTime(msg)
    --log("=========shopHandler.ResRefShopTime====>");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        logicMgr.ShopManager.refreshShopTime(msg);
    end
end

--购买物品返回
function shopHandler.ResBuyMsg(msg)
    --log("=========shopHandler.ResBuyMsg====>");
    --dataTable.PrintTable(msg);
    if msg.state == 0 then
        if msg.shopId == 11000 then
            FireEvent(Config.EventType.BuyPond)
        elseif msg.shopId == 200002 then
            FireEvent(Config.EventType.DrawBuySuccess)

        end

        logicMgr.ShopManager.refreshShopBuyItem(msg);
    end
end

--发送商店数据请求
function shopHandler.reqShopDataList(ShopType)
    local req = ReqShopItemListMessage.New();
    req.shopId = tonumber(ShopType);
    sendReqMessage(req);
end

--发送刷新请求
function shopHandler.reqRefShopData(shopId,refreshTimes)
    local req = ReqRefreshShopMessage.New();
    req.shopId = tonumber(shopId);
    req.times = tonumber(refreshTimes);
    sendReqMessage(req);
end

--发送购买商品请求
function shopHandler.reqBuyShopItem(itemData, countNum)
    local req = ReqBuyItemMessage.New();
    req.shopId = tonumber(itemData.shopId);
    req.shopItemId = itemData.shopItemId;
    req.shopItemModelId = tonumber(itemData.shopItemModelId);
    req.itemModelId = tonumber(itemData.itemModelId);
    req.monyType = tonumber(itemData.monyType);
    req.num = countNum or itemData.num or 1;
    sendReqMessage(req);
end

